using DG.Tweening;
using UnityEngine;
using UnityEngine.Events;

namespace Custom.Daily.Toolkit
{
    public class ToggleController : MonoBehaviour
    {
        public GameObject maskImage;
        public GameObject mouseHoverImage;

        public UnityEvent<bool> onValueChanged;

        private bool _isOn;
        public bool isOn
        {
            get { return _isOn; }
            set
            {
                if(value != _isOn)
                {
                    _isOn = value;
                    StatusChanged();
                } 
            }
        }

        private void StatusChanged()
        {
            maskImage.SetActive(_isOn);
            onValueChanged?.Invoke(_isOn);
        }

        public void ToggleClick()
        {
            isOn = !isOn;
        }

        public void MouseHoverEnter()
        {
            mouseHoverImage.SetActive(true);
            mouseHoverImage.transform.DOScale(new Vector3(1f, 1f, 1f), 0.08f);
        }
        public void MouseHoverExit()
        {
            mouseHoverImage.transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), 0.08f).OnComplete(() =>
            {
                mouseHoverImage.SetActive(false);
            });
        }
    }
}

